package com.GameSpace.CoreAssets;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;


public class StatisticManager{

	public StatisticsDBAdapter dbAdapter;
	
	public StatisticManager(){
		
	}
	
	public StatisticManager(Context ctx){
		dbAdapter=new StatisticsDBAdapter(ctx);
	}
	
	public void addStatistic(Statistic s){		 
		
		dbAdapter.open();
		dbAdapter.insertStatistic(s);
		dbAdapter.close();
	}
	
	public void deleteStatistic(String statisticLabel){
		dbAdapter.open();
		dbAdapter.deleteStatistic(statisticLabel);
		dbAdapter.close();
	}
	
	public void updateStatistic(Statistic s){
		dbAdapter.open();
		dbAdapter.updateStatistic(s);
		dbAdapter.close();
	}
	
	public Statistic getStatistic(String statisticLabel){
		dbAdapter.open();
		Cursor c = dbAdapter.getStatistic(statisticLabel);
		Statistic s = new Statistic();
		while(c.moveToNext()){	
			s.setType(c.getString(1));
			s.setLabel(c.getString(2));
			s.setValue(c.getString(3));
		}
		dbAdapter.close();
		return s;
	}
	
	public ArrayList<Statistic> getAllStatistics(){
		
		ArrayList<Statistic> statistics;
		dbAdapter.open();
		Cursor c = dbAdapter.getAllStatistics();
		statistics = new ArrayList<Statistic>();
		while(c.moveToNext()){
			Statistic s = new Statistic();
			s.setPlayerName(c.getString(1));
			s.setType(c.getString(2));
			s.setLabel(c.getString(3));
			s.setValue(c.getString(4));
			statistics.add(s);
		}
		dbAdapter.close();
		return statistics;
	}
	

}